<template>
  <Modal v-model="modal" :title="title">
    <div class="tag-modal">
      <Form :model="form" :label-width="110" ref="form" :rules="rules">
        <FormItem label="审核原因:">
          <span>{{msg}}</span>
        </FormItem>
        <FormItem label="审核是否通过">
          <RadioGroup v-model="form.auditStatus">
            <Radio :label="2">是</Radio>
            <Radio :label="1">否</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="备注">
          <Input
            v-model="form.auditRemark"
            type="textarea"
            :autosize="{minRows: 2,maxRows: 5}"
            placeholder="审核备注"
          />
        </FormItem>
      </Form>
    </div>
    <div slot="footer">
      <Button @click="modal = false" size="large" type="text">取消</Button>
      <Button :loading='btnLoading' @click="onSave" type="primary" size="large">确定</Button>
    </div>
  </Modal>
</template>
<script>
export default {
  data() {
    return {
      id: null,
      modal: false,
      title: "经销商业务员审核",
      rules: {
        name: [{ required: true, message: '请输入名称', trigger: "blur" }]
      },
      form: {
        auditRemark: '',
        auditStatus: 2,
      },
      row : {},
      btnDisabled: false,
    };
  },
  computed: {
    msg() {
      return Array.isArray(this.row) ? '签约/解约' : this.row.contractStatus===1?'解约':'签约'
    },
  },
  methods: {
    openModal(row) {
      this.row = row
      this.modal = true;
    },
    closeModal() {
      this.modal = false;
    },
    onSave() {
      this.btnLoading = true;
      let text = '审核'
      let url = '/distributor_salesman/audit'
      let arr = Array.isArray(this.row) ? this.row.map(item => item.id) : [this.row.id]
      let param = {
        cids: arr,
        auditRemark: this.form.auditRemark,
        auditStatus: this.form.auditStatus
      };
      this.$jsonPost(url, param)
        .then(data => {
          this.btnLoading = false
          this.$Notice.success({
            title: `${text}成功`
          });
          this.$emit("complete");
          this.closeModal();
        })
        .catch(() => {
          this.btnLoading = false;
        })
      }
  }
};
</script>

